package com.javaweb.homework;

import com.javaweb.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author: XiangHu
 * @date: 2025年02月27日  19:09
 * @describe:
 */
@WebServlet("/update")
public class update extends HttpServlet {
    // 处理get请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置请求编码
        req.setCharacterEncoding("UTF-8");
        // 设置响应编码
        resp.setCharacterEncoding("UTF-8");
        // 设置请求参数
        String id = req.getParameter("id");
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String cellphone = req.getParameter("cellphone");
        String address = req.getParameter("address");
        String gender = req.getParameter("gender");
        JDBCUtils.update("update stu set name = ?,age = ?,cellphone = ?,address = ?,gender = ? where id = ?",
                name,age,cellphone,address,gender,id);
        resp.getWriter().print("更新成功！");
    }
}
